﻿using System.Windows;
using DSPL.Services;
using DSPL.Contracts;
using DSPL.Common;
using System.Data;
using DSPL.Services.Services;
using DSPL.Contracts.Common;
using DSPL.Contracts.ViewModel;
using DSPL.Contracts.Command;
using DSPL.Finac.Common;

namespace DSPL.Finac.ViewModel
{
    public class UnitOfMeasureMasterViewModel : BaseViewModel
    {
        private bool isUnitCodeFocused;
        private bool isUnitNameFocused;

        #region Define properties

        public bool IsUnitCodeFocused
        {
            get { return isUnitCodeFocused; }
            set
            {
                isUnitCodeFocused = value;
                this.OnPropertyChanged("IsUnitCodeFocused");
            }
        }

        public bool IsUnitNameFocused
        {
            get { return isUnitNameFocused; }
            set
            {
                isUnitNameFocused = value;
                this.OnPropertyChanged("IsUnitNameFocused");

            }
        }
        #endregion


        #region Constructor

        public UnitOfMeasureMasterViewModel()
            : base()
        {
            MessageTitle = "Unit Of Measure Master";
        }

        #endregion
        /// <summary>
        /// Validate mandatory data before save
        /// </summary>
        /// <param name="obj"></param>
        protected override void PreDataValidateExecuted(object obj)
        {
            IsUnitCodeFocused = false;
            IsUnitNameFocused = false;

            var messageService = new MessageService();
            if (CurrentRow["UnitCode"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.UnitCodeNotEmpty,MessageTitle, MessageType.InfoOK);
                IsUnitCodeFocused = true;
                this.IsValid = false;
                return;
            }

            if (CurrentRow["UnitName"].ToString().Trim() == string.Empty)
            {
                messageService.ShowMessage(MessageText.UnitNameNotEmpty,MessageTitle, MessageType.InfoOK);
                IsUnitNameFocused = true;
                this.IsValid = false;
                return;
            }
            this.IsValid = true;
        }
    }
}